DROP FUNCTION IF EXISTS "public"."count_obton"();
CREATE OR REPLACE FUNCTION "public"."count_obton"()
  RETURNS "pg_catalog"."int4" AS $BODY$
declare
counts integer;

begin select sum(obton) into counts from "public"."newstockouts";
return counts;
end;

$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;





DROP FUNCTION IF EXISTS "public"."upstoragefee"();
CREATE OR REPLACE FUNCTION "public"."upstoragefee"()
  RETURNS "pg_catalog"."trigger" AS $BODY$ 
BEGIN 
IF NEW.storsgefee IS NULL
THEN 
    SET NEW.storsgefee =-1;
END IF;
RETURN NULL;
END; 
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
CREATE TRIGGER "updatestfee" BEFORE UPDATE OF "storsgefee" ON "public"."newstockouts"
FOR EACH ROW
EXECUTE PROCEDURE "public"."upstoragefee"();